package com.onec.service.customer.service.base;


import cn.hutool.core.date.DateUtil;
import com.onec.service.api.dto.response.customer.MerchantResp;
import com.onec.service.api.enums.error.MerchantErrorEnum;
import com.onec.service.customer.entity.merchant.MerchantBusiness;
import com.onec.service.customer.entity.merchant.MerchantInfo;


/**
 * 机构接口返回基类：
 *
 * @author onec
 */
public class BaseMerchantInfoServiceImpl implements CustomerService {

    /**
     * @param merchantErrorEnum
     * @return AgentInfoResp
     */
    protected MerchantResp respErrorMerchant(MerchantErrorEnum merchantErrorEnum) {
        MerchantResp merchantResp = new MerchantResp();
        merchantResp.setCode(merchantErrorEnum.getIndex());
        merchantResp.setMessage(merchantErrorEnum.getMsg());

        return merchantResp;
    }

    /**
     * @param merchantInfo
     * @param merchantBusiness
     * @return AgentInfoResp
     */
    protected MerchantResp respMerchantInfo(MerchantInfo merchantInfo, MerchantBusiness merchantBusiness) {
        MerchantResp merchantResp = respErrorMerchant(MerchantErrorEnum.SUCCESS);
        merchantResp.setContacts(merchantInfo.getContacts());
        merchantResp.setCreateTime(DateUtil.formatTime(merchantInfo.getCreateTime()));
        merchantResp.setUpdateTime(DateUtil.formatDateTime(merchantInfo.getUpdateTime()));
        merchantResp.setName(merchantInfo.getName());
        merchantResp.setMerchantNo(merchantInfo.getCode());
        merchantResp.setPhone(merchantInfo.getPhone());

        merchantResp.setRate(merchantBusiness.getMerchantRate());
        merchantResp.setFee(merchantBusiness.getMerchantFee());
        merchantResp.setProduct(merchantBusiness.getProduct().name());
        merchantResp.setBusinessNo(merchantBusiness.getBusinessNo());
        return merchantResp;
    }
}
